-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search - Adds the ability to search within an LCV and create an Alias without a context #16
base: main
Are you sure you want to change the base?
Conversation
Search.html
added search and create alias
With search and alias
app/uid/forms.py
Outdated
class AliasForm(forms.Form): | ||
alias = forms.CharField(max_length=255, required=True) # The alias name | ||
context = forms.CharField(max_length=255, required=False) # Context as a string (the term's name) | ||
|
||
def save(self): | ||
# Create and save Alias | ||
alias = Alias(alias=self.cleaned_data['alias'], context=self.cleaned_data.get('context')) | ||
alias.save() | ||
|
||
# Optionally, if context is provided, link to the NeoTerm | ||
if alias.context: | ||
term = NeoTerm.nodes.get_or_none(name=alias.context) | ||
if term: | ||
alias.link_to_term(term) # Link this alias to the found NeoTerm | ||
|
||
return alias |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anyway to make this work with NeoAlias?
app/uid/models.py
Outdated
class Alias(StructuredNode): | ||
alias = StringProperty(unique_index=True) # The alias name | ||
context = StringProperty(required=False, default=None) # Optional context | ||
points_to = RelationshipTo('NeoTerm', 'POINTS_TO') # The relationship to NeoTerm | ||
context_error = StringProperty(required=False) # Optional field to store error message | ||
|
||
def __str__(self): | ||
return self.alias | ||
|
||
def link_to_term(self, neo_term): | ||
"""Link this alias to a NeoTerm.""" | ||
if isinstance(neo_term, NeoTerm): | ||
self.points_to.connect(neo_term) | ||
|
||
def save(self, *args, **kwargs): | ||
"""Override the save method to automatically link the alias to a NeoTerm if context is provided.""" | ||
context_error = None # Initialize an error variable | ||
|
||
# Call the parent class save method | ||
super(Alias, self).save(*args, **kwargs) | ||
|
||
if self.context: | ||
# Get or create the NeoTerm based on the context | ||
term, created = NeoTerm.get_or_create(uid=self.context) | ||
if term: | ||
# Set relationships for the NeoTerm, including the alias | ||
term.set_relationships(definition_node, context_node, self) | ||
else: | ||
context_error = f"No matching NeoTerm found for context: {self.context}" | ||
else: | ||
# If no context is provided, link to a default NeoTerm (first available NeoTerm) | ||
term = NeoTerm.nodes.first() # You can change this to a specific fallback logic | ||
if term: | ||
self.link_to_term(term) | ||
else: | ||
context_error = "No NeoTerm available to link." | ||
|
||
# If an error was encountered, raise it so it can be caught in the view or returned to the form | ||
if context_error: | ||
self.context_error = context_error # Store the error message in the instance | ||
self.save() | ||
|
||
return context_error # Return the error message, if any | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the way you wrote this class. Is there anyway you can make NeoAlias work in a similar way?
Updated views.py for alias with/without context and using Neoalias. Commend old working code.
Updated Forms.py to include new NeoAlias changes.
Updated models.py to manage the linking NeoAlias, NeoTerm and NeoContext even if context is not provided default to first available NeoTerm. THis is now handled by the addition of the NeoAliasManager class.
… general search feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bay is going to move the search functionality to the Core application from under UID and then merge into main. Search is working, Alias without context is working for existing defintions that have a TermID associated with them. Alias without context on CSV Upload for new defintions still has to be implemented at a later date/
How to Test
username: neo4j
andpassword: password
match(n) return n
to view all nodes.